import React from 'react'

export const withPosition = Component => {
  return class extends React.Component {
    constructor () {
      super()
      this.state = {
        position: {
          x: 0,
          y: 0
        }
      }
    }
    move = e => {
      console.log(e)
      this.setState({
        position: {
          x: e.clientX,
          y: e.clientY
        }
      })
    }
    componentDidMount () {
      window.addEventListener('mousemove', this.move)
    }
    componentWillUnmount () {
      window.removeEventListener('mousemove', this.move)
    }
    render () {
      return <Component position={this.state.position} {...this.props} />
    }
  }
}
